import 'dart:convert';
import 'dart:ui' as prefix0;

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_aygsh/liz_mine/set/ArticleDetail.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../util/Toast.dart';
import '../liz_mine/address/MyAddress.dart';
import '../base/Constant.dart';
// import 'package:panda/base/SignType.dart';
import '../http/Api.dart';
import '../entity/address_entity.dart';
import '../http/HttpUtil.dart';
import '../util/AppSaveInfoUtil.dart';
import '../entity/shop_car_entity.dart';
import '../util/LoadingUtil.dart';
import '../util/SignUtil.dart';
import '../liz_mine/set/Identity.dart';
import 'package:xlive_switch/xlive_switch.dart';
import '../liz_home/goods/chooseCoupon.dart';
import '../liz_mine/order/OrderPay.dart';
import '../event/LoginEvent.dart';
import '../base/application.dart';

class BuyGoodsByCarPage extends StatefulWidget {
  String total = "0.00";
  List<MyShopCarDataData> datas;
  BuyGoodsByCarPage({Key key, this.datas, this.total}) : super(key: key);
  _BuyGoodsByCarPageState createState() => _BuyGoodsByCarPageState();
}

class _BuyGoodsByCarPageState extends State<BuyGoodsByCarPage>
    with WidgetsBindingObserver {
  var selectAddress = "";
  String detailAddress = "";
  var selectId = "";
  var selectNameAndPhone = "", selectName = '';
  String token = "";
  Map userMap = null;
  String remark = "";
  String truename = '';
  String id_num = '';
  bool check = true;
  bool isID = false;
  String allCoupon = '0';
  double save_money = 0, postage = 0;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getString(TOKEN).then((value) {
      token = value;
      getAUTHRESULT();
      loadList();
    });
    int n = 0;
    for (int i = 0; i < widget.datas.length; i++) {
      widget.datas[i].coupon="0";
            widget.datas[i].coupon_record_id="";

      if (double.parse(widget.datas[n].postage) <
          double.parse(widget.datas[i].postage)) {
        n = i;
      }
    }
    for (int i = 0; i < widget.datas.length; i++) {
      if (n != i) {
        widget.datas[i].postage = '0';
      }
    }
    for (int i = 0; i < widget.datas.length; i++) {
      save_money += double.parse(widget.datas[i].goods_num) *
          double.parse(widget.datas[i].save_money == "null"
              ? "0"
              : widget.datas[i].save_money);
      // double.parse(widget.datas[i].goods_num) *
      postage += double.parse(
          widget.datas[i].postage == "null" ? "0" : widget.datas[i].postage);
    }
    if (APPLIC.userInfoMap['user_msg']['group_id'] == 1) {
      save_money = 0;
    }
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    return Container(
      child: new Scaffold(
          appBar: AppBar(
            leading: new IconButton(
              icon: new Icon(Icons.arrow_back, color: Colors.black),
              onPressed: () {
                widget.datas.clear();
                Navigator.of(context).pop('购物车');
                // Navigator.pop(context);
              },
            ),
            title: Text('提交订单',
                style: TextStyle(
                    fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                    color: black)),
            backgroundColor: white,
            brightness: Brightness.light,
            iconTheme: IconThemeData(color: black_99),
            elevation: 1.0,
          ),
          body: CustomScrollView(shrinkWrap: true, slivers: <Widget>[
            SliverToBoxAdapter(
                child: Container(
                    child: Column(children: <Widget>[
              Container(
                color: white,
                margin: EdgeInsets.all(kMargin15),
                padding: EdgeInsets.all(15),
                child: new Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    selectAddress == ""
                        ? Container()
                        : Image.asset('images/order_adress_pre.png'),
                    Expanded(
                      child: GestureDetector(
                        onTap: () {
                          Navigator.of(context).push<AddressListDataData>(
                              MaterialPageRoute(builder: (context) {
                            return MyAddressPage(
                              type: 1,
                            );
                          })).then((AddressListDataData data) {
                            print(data);
                            setState(() {
                              selectAddress =
                                  data.province + data.city + data.county;
                              detailAddress = data.detail_address;
                              selectId = data.id;
                              selectNameAndPhone =
                                  data.consignee + "  " + data.contact_number;
                              selectName = data.consignee;
                            });
                          });
                        },
                        child: selectAddress == ""
                            ? Padding(
                                padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                                child: Column(
                                  children: <Widget>[
                                    Image.asset('images/order_adress_nor.png'),
                                    Container(
                                      height: kMargin30,
                                    ),
                                    Text('请选择收货地址',
                                        style: TextStyle(
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(NORMAL_FONT_SIZE),
                                            color: Colors.black45))
                                  ],
                                ))
                            : Padding(
                                padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                                child: new Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: <Widget>[
                                    Text(selectAddress,
                                        style: TextStyle(
                                            color: black,
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(SMALL_FONT_SIZE))),
                                    Text(detailAddress,
                                        style: TextStyle(
                                            color: black,
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(40),
                                            fontWeight: FontWeight.w500)),
                                    Padding(
                                      padding: EdgeInsets.fromLTRB(0, 8, 0, 0),
                                      child: Text(selectNameAndPhone,
                                          style: TextStyle(
                                            color: black_99,
                                            fontSize: ScreenUtil.getInstance()
                                                .setSp(SMALL_FONT_SIZE),
                                          )),
                                    ),
                                    Padding(
                                        padding:
                                            EdgeInsets.fromLTRB(0, 8, 0, 0),
                                        child: Text('(收货不便时，请选择自提服务)',
                                            style: TextStyle(
                                                color: Colors.red,
                                                fontSize:
                                                    ScreenUtil.getInstance()
                                                        .setSp(
                                                            SMALL_FONT_SIZE)))),
                                  ],
                                ),
                              ),
                      ),
                    ),
                    GestureDetector(
                      onTap: () {
                        Navigator.of(context).push<AddressListDataData>(
                            MaterialPageRoute(builder: (context) {
                          return MyAddressPage(
                            type: 1,
                          );
                        })).then((AddressListDataData data) {
                          // print(data);
                          setState(() {
                            selectAddress = data.province +
                                data.city +
                                data.county +
                                data.detail_address;
                            selectId = data.id;
                            selectNameAndPhone =
                                data.consignee + "  " + data.contact_number;
                            selectName = data.consignee;
                          });
                        });
                      },
                      child: Container(
                        color: white,
                        child: Icon(Icons.arrow_forward_ios),
                      ),
                    )
                  ],
                ),
              ),
            ]))),
            SliverList(
              delegate: SliverChildBuilderDelegate(
                (context, index) {
                  if (widget.datas.length > 0) {
                    return the_row(context, index);
                  } else {
                    return Visibility(
                      visible: true,
                      child: Container(width: 0, height: 0),
                    );
                  }
                },
                childCount: widget.datas.length,
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.all(kMargin15),
                padding: EdgeInsets.fromLTRB(10, 8, 10, 0),
                color: white,
                child: Column(
                  children: <Widget>[
                    Row(
                      children: <Widget>[
                        Text(
                          '支付人',
                          style: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(SMALL_FONT_SIZE)),
                        ),
                        Container(
                          width: kMargin10,
                          height: 1,
                        ),
                        Expanded(
                          flex: 1,
                          child: Text(
                            truename + ' ' + id_num,
                            style: TextStyle(
                                color: black,
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(SMALL_FONT_SIZE)),
                          ),
                        ),
                        GestureDetector(
                            onTap: () {
                              Navigator.of(context)
                                  .push(MaterialPageRoute(builder: (context) {
                                return new IdentityPage();
                              }));
                            },
                            child: Text(
                              '更换',
                              style: TextStyle(
                                  color: Colors.blue,
                                  fontSize: ScreenUtil.getInstance()
                                      .setSp(SMALL_FONT_SIZE)),
                            ))
                      ],
                    ),
                    Container(
                      width: ScreenUtil.getInstance().setWidth(750),
                      height: kMargin15,
                    ),
                    Row(
                      children: <Widget>[
                        Image.asset('images/order_pay.png'),
                        Container(
                          width: kMargin15,
                          height: 1,
                        ),
                        Expanded(
                          child: Text(
                            '海关规定购买跨境商品，须验证实际支付人身份信息，否则导致无法清关',
                            style: TextStyle(
                                color: Colors.grey,
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(NORMAL_FONT_SIZE)),
                          ),
                        )
                      ],
                    ),
                    Container(
                      width: ScreenUtil.getInstance().setWidth(750),
                      height: kMargin15,
                    ),
                  ],
                ),
              ),
            ),
            SliverToBoxAdapter(
              child: Container(
                  margin: EdgeInsets.all(kMargin15),
                  color: white,
                  padding: EdgeInsets.fromLTRB(10, 8, 10, 0),
                  child: Column(
                    children: <Widget>[
                      Container(
                        width: ScreenUtil.getInstance().setWidth(750),
                        height: kMargin15,
                      ),
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Text('商品总额',
                                style: TextStyle(
                                    color: black,
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(NORMAL_FONT_SIZE))),
                          ),
                          Text(
                            MONEY + widget.total,
                            style: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE),
                              color: black,
                            ),
                          ),
                        ],
                      ),
                      Container(
                        width: ScreenUtil.getInstance().setWidth(750),
                        height: kMargin40,
                      ),
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Text('运费',
                                style: TextStyle(
                                    color: black,
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(NORMAL_FONT_SIZE))),
                          ),
                          Text(
                            '$postage',
                            style: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE),
                              color: black,
                            ),
                          ),
                        ],
                      ),
                      Container(
                        width: ScreenUtil.getInstance().setWidth(750),
                        height: kMargin40,
                      ),
                      Row(
                        children: <Widget>[
                          Expanded(
                            child: Text('本次节省',
                                style: TextStyle(
                                    color: black,
                                    fontSize: ScreenUtil.getInstance()
                                        .setSp(NORMAL_FONT_SIZE))),
                          ),
                          Text(
                            formatNum(save_money,2),
                            style: TextStyle(
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE),
                              color: Colors.red,
                            ),
                          ),
                        ],
                      ),
                      Container(
                        width: ScreenUtil.getInstance().setWidth(750),
                        height: kMargin30,
                      ),
                    ],
                  )),
            ),
            // SliverToBoxAdapter(
            //   child: Container(
            //     margin: EdgeInsets.all(kMargin15),
            //     color: white,
            //     padding: EdgeInsets.fromLTRB(10, 8, 10, 10),
            //     child: Row(
            //       children: <Widget>[
            //         Expanded(
            //           child: Text('发票',
            //               style: TextStyle(
            //                   color: black,
            //                   fontSize: ScreenUtil.getInstance()
            //                       .setSp(NORMAL_FONT_SIZE))),
            //         ),
            //         Text(
            //           '确认收货后可申请发票',
            //           style: TextStyle(
            //             fontSize:
            //                 ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE),
            //             color: black,
            //           ),
            //         ),
            //         Container(
            //             margin: EdgeInsets.all(kMargin15),
            //             child: Image.asset('images/shangpin_more.png'))
            //       ],
            //     ),
            //   ),
            // ),
            SliverToBoxAdapter(
              child: Container(
                margin: EdgeInsets.all(kMargin15),
                color: white,
                padding: EdgeInsets.fromLTRB(10, 8, 10, 10),
                child: Row(
                  children: <Widget>[
                    Expanded(
                      child: Text('本人已知悉并同意',
                          style: TextStyle(
                              color: black,
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE))),
                    ),
                    Expanded(
                      child: GestureDetector(
                        onTap: () {
                          Navigator.of(context)
                              .push(MaterialPageRoute(builder: (context) {
                            return new ArticleDetailPage(
                              article_id: "18",
                            );
                          }));
                        },
                        child: Text('用户购买协议',
                            style: TextStyle(
                                color: Colors.green,
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(NORMAL_FONT_SIZE))),
                      ),
                    ),
                    XlivSwitch(
                      value: this.check,
                      activeColor: mainColor, // 激活时原点颜色
                      unActiveColor: Colors.grey,
                      onChanged: (bool val) {
                        checkInform();
                      },
                    )
                  ],
                ),
              ),
            ),
            SliverToBoxAdapter(
                child: Padding(
              padding: EdgeInsets.all(10),
              child: Row(
                children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: Text(
                      MONEY +
                          formatNum(
                              (double.parse(widget.total) -
                                  double.parse(allCoupon) +
                                  postage -
                                  save_money),
                              2),
                      style: TextStyle(
                          fontSize: ScreenUtil.getInstance().setSp(40),
                          color: mainColor),
                    ),
                  ),
                  new Container(
                    height: 35,
                    decoration: new BoxDecoration(
                        color: mainColor,
                        borderRadius: BorderRadius.circular(40.0)),
                    child: new FlatButton(
                      child: new Padding(
                        padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                        child: new Text(
                          "确定下单",
                          style: new TextStyle(
                              color: Colors.white,
                              fontSize: ScreenUtil.getInstance()
                                  .setSp(NORMAL_FONT_SIZE)),
                        ),
                      ),
                      onPressed: () {
                        if (isID == false) {
                          Toast.toast(context, msg: '请进行实名认证');
                          // Fluttertoast.showToast(msg: '请进行实名认证');
                          return;
                        }
                        if (check == false) {
                          Toast.toast(context, msg: '请同意协议');
                          return;
                        }
                        if (selectId == "") {
                          Toast.toast(context, msg: '请选择收货地址');
                          // Fluttertoast.showToast(msg: "请选择收货地址");
                          return;
                        }

                        showDialog(
                            context: context,
                            barrierDismissible: false,
                            builder: (_) {
                              return new NetLoadingDialog(
                                loadingText: "下单中...",
                                bgColor: Color.fromARGB(255, 0, 0, 0),
                                requestCallBack: null,
                                outsideDismiss: false,
                              );
                            });
                        buy();
                      },
                    ),
                  )
                ],
              ),
            ))
          ])),
    );
  }

  String formatNum(double num, int postion) {
    if ((num.toString().length - num.toString().lastIndexOf(".") - 1) <
        postion) {
      return num.toStringAsFixed(postion)
          .substring(0, num.toString().lastIndexOf(".") + postion + 1)
          .toString();
    } else {
      return num.toString()
          .substring(0, num.toString().lastIndexOf(".") + postion + 1)
          .toString();
    }
  }

  Widget the_row(BuildContext context, int index) {
    return Container(
      margin: EdgeInsets.all(kMargin15),
      padding: EdgeInsets.all(15),
      color: white,
      // padding: EdgeInsets.only(left: 15, right: 15, bottom: 10),
      child: new Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          widget.datas[index].img == ""
              ? Image.asset(
                  'images/pic_default.png',
                  width: ScreenUtil.getInstance().setHeight(DP_120),
                  height: ScreenUtil.getInstance().setHeight(DP_120),
                  fit: BoxFit.fill,
                )
              : Image.network(
                  Api.ImgBaseUrl + widget.datas[index].img,
                  width: ScreenUtil.getInstance().setHeight(DP_120),
                  height: ScreenUtil.getInstance().setHeight(DP_120),
                  fit: BoxFit.fill,
                ),
          Expanded(
            flex: 1,
            child: Container(
              padding: EdgeInsets.fromLTRB(10, 0, 5, 5),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text(
                    widget.datas[index].goods_name,
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                        fontSize: ScreenUtil.getInstance()
                            .setSp(NORMAL_FONT_SIZE + 2),
                        color: black,
                        fontWeight: FontWeight.w500),
                  ),
                  Padding(
                    padding: EdgeInsets.fromLTRB(0, 5, 5, 2),
                    child: Text(
                      widget.datas[index].sku_str +
                          "    数量:" +
                          widget.datas[index].goods_num,
                      style: TextStyle(
                          fontSize:
                              ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE),
                          color: black_99),
                    ),
                  ),
                  Text(
                    '¥' + widget.datas[index].price,
                    style: TextStyle(
                        fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                        color: mainColor),
                  ),
                  GestureDetector(
                      onTap: () {
                        List<String> ids=new List();
                        for (int i = 0; i < widget.datas.length; i++) {
                          ids.add(widget.datas[i].coupon_record_id);
                          }
                        Navigator.of(context)
                            .push<Map>(MaterialPageRoute(builder: (context) {
                          return ChooseCoupon(
                            goods_id: widget.datas[index].goods_id,
                            ids:ids
                          );
                        })).then((Map coupon) {
                          if(coupon==null){
                            return ;
                          }
                          MyShopCarDataData d = widget.datas[index];
                          d.coupon_record_id =
                              coupon['coupon_record_id'].toString();
                          d.coupon = coupon['money'].toString();
                          allCoupon = '0';
                          for (int i = 0; i < widget.datas.length; i++) {
                            allCoupon = (double.parse(allCoupon) +
                                    double.parse(widget.datas[i].coupon=='null'?'0':widget.datas[i].coupon))
                                .toString();
                          }
                          setState(() {});
                        });
                      },
                      child: Container(
                        margin: EdgeInsets.all(kMargin15),
                        color: white,
                        padding: EdgeInsets.fromLTRB(10, 8, 10, 10),
                        child: Row(
                          children: <Widget>[
                            Expanded(
                              child: Text('优惠券',
                                  style: TextStyle(
                                      color: black,
                                      fontSize: ScreenUtil.getInstance()
                                          .setSp(NORMAL_FONT_SIZE))),
                            ),
                            Text(
                              widget.datas[index].coupon == null||widget.datas[index].coupon=='0'
                                  ? '选择'
                                  : widget.datas[index].coupon + '元',
                              style: TextStyle(
                                fontSize: ScreenUtil.getInstance()
                                    .setSp(NORMAL_FONT_SIZE),
                                color: black,
                              ),
                            ),
                            Container(
                                margin: EdgeInsets.all(kMargin15),
                                child: Image.asset('images/shangpin_more.png'))
                          ],
                        ),
                      )),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  checkInform() async {
    if (check == true) {
      setState(() {
        check = false;
        // saveBoolean(INFORM, check);
      });
      return;
    } else {
      if (check == false) {
        setState(() {
          check = true;
          // saveBoolean(INFORM, check);
        });
        return;
      }
    }
  }

  buy() async {
    if (truename != selectName) {
      Navigator.of(context).pop(1);
      Toast.toast(context, msg: '收货人应与实名认证信息一致');
      return;
    }
    Map map = new Map();
    map['token'] = token;
    List<Map> goodsList = new List();
    for (int i = 0; i < widget.datas.length; i++) {
      Map map1 = new Map();
      map1['"shopcart_id"'] = widget.datas[i].id;
      map1['"goods_num"'] = widget.datas[i].goods_num;
      if (widget.datas[i].coupon_record_id == null ||
          widget.datas[i].coupon_record_id == '') {
        map1['"coupon_record_id"'] = '0';
      } else {
        map1['"coupon_record_id"'] = widget.datas[i].coupon_record_id;
      }

      if (widget.datas[i].sku_arr.length == 0) {
        // map1['"goods_sku"'] = null;
      } else {
        Map map2 = new Map();
        map2['"attribute_id"'] = widget.datas[i].sku_arr[0].attribute_id;
        map2['"value"'] = widget.datas[i].sku_arr[0].value;
        map2['"attribute_name"'] = widget.datas[i].sku_arr[0].attribute_name;
        map1['"goods_sku"'] = map2;
      }
      goodsList.add(map1);
    }
    Navigator.of(context).pop(1);
    map['goodslist'] = goodsList.toString();
    map['remark'] = "\"" + remark + "\"";
    map['address_id'] = selectId;
    map['sign_type'] = createSignType(Api.URL_ORDER_CARTQRDER);
    Response<String> response =
        await HttpUtil().post(Api.URL_ORDER_CARTQRDER, data: getSign(map));
    print(response);

    userMap = json.decode(response.data);
    int code = userMap['code'];
    if (code == 1) {
      // Fluttertoast.showToast(msg: '下单成功');
      Toast.toast(context, msg: '下单成功');
      Navigator.of(context).pop();
      APPLIC.eventBus.fire(LoginEvent());
      Navigator.of(context).push(MaterialPageRoute(builder: (context) {
        return new OrderPayPage(
            orderId: userMap['data']['order_id'].toString(),
            title: userMap['data']['title'].toString(),
            discount: userMap['data']['discount'].toString(),
            orderNum: userMap['data']['order_num'].toString(),
            totalMoney: userMap['data']['pay_price'].toString());
      }));
    } else {
      Toast.toast(context, msg: userMap['msg']);
      // Fluttertoast.showToast(msg: userMap['msg']);
      userMap = null;
    }
  }

  loadList() async {
    Map map = new Map.from({
      "sign_type": createSignType(Api.URL_ADDRESS_LIST),
      "token": token,
      "p": 1,
      "per": "100"
    });
    print(map);
    Response<String> response =
        await HttpUtil().post(Api.URL_ADDRESS_LIST, data: getSign(map));
    Map userMap = json.decode(response.data);
    if (userMap['code'] != 1) {
      // Fluttertoast.showToast(msg: userMap['msg']);
      Toast.toast(context, msg: userMap['msg']);
      return;
    }
    AddressListEntity homeListEntity = new AddressListEntity.fromJson(userMap);
    if (mounted)
      for (int i = 0; i < homeListEntity.data.datas.length; i++) {
        if ("Y" == homeListEntity.data.datas[i].is_default) {
          selectAddress = homeListEntity.data.datas[i].province +
              homeListEntity.data.datas[i].city +
              homeListEntity.data.datas[i].county;
          detailAddress = homeListEntity.data.datas[i].detail_address;
          selectId = homeListEntity.data.datas[i].id;
          selectNameAndPhone = homeListEntity.data.datas[i].consignee +
              "  " +
              homeListEntity.data.datas[i].contact_number;

          selectName = homeListEntity.data.datas[i].consignee.toString();
          break;
        }
      }

    setState(() {});
  }

  getAUTHRESULT() async {
    //获取实名认证信息
    Map map = new Map.from({
      "sign_type": createSignType(Api.URL_USER_AUTHRESULT),
      'token': token,
    });
    Response<String> response =
        await HttpUtil().post(Api.URL_USER_AUTHRESULT, data: getSign(map));
    userMap = json.decode(response.data);
    int code = userMap['code'];

    if (code == 1) {
      if (userMap['data']['authMsg'] is List &&
          userMap['data']['authMsg'].length == 0) {
        setState(() {
          isID = false;
        });
        // Fluttertoast.showToast(msg: '实名信息未通过审核或未提交审核');
        showDialog(
          context: context,
          builder: (context) => new AlertDialog(
            title: new Text('提示'),
            content: new Text('实名信息未通过审核或未提交审核'),
            actions: <Widget>[
              new FlatButton(
                onPressed: () => Navigator.of(context).pop(false),
                child: new Text(
                  '知道了',
                  style: TextStyle(color: Colors.grey),
                ),
              ),
              new FlatButton(
                onPressed: () => Navigator.of(context).pop(false),
                child: new Text(
                  '联系客服',
                  style: TextStyle(color: Colors.grey),
                ),
              ),
              new FlatButton(
                onPressed: () {
                  Navigator.of(context)
                      .push(MaterialPageRoute(builder: (context) {
                    return new IdentityPage();
                  }));
                },
                child: new Text('实名认证', style: TextStyle(color: mainColor)),
              ),
            ],
          ),
        );
      } else {
        print('===实名认证000===');
        print(userMap);
        setState(() {
          isID = true;
          truename = userMap['data']['authMsg']['truename'];
          id_num = userMap['data']['authMsg']['id_num'];
        });
      }
    }
  }
}
